﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Game.model;
using lineage2.commons.util;

namespace Game.ai
{
    public class DoorAI:CharacterAI
{
	/**
	 * Constructor for DoorAI.
	 * @param actor DoorInstance
	 */
	public DoorAI(DoorInstance actor):base(actor)
	{
		//super(actor);
	}
	
	/**
	 * Method onEvtTwiceClick.
	 * @param player Player
	 */
	public void onEvtTwiceClick(Player player)
	{
	}
	
	/**
	 * Method onEvtOpen.
	 * @param player Player
	 */
	public void onEvtOpen(Player player)
	{
	}
	
	/**
	 * Method onEvtClose.
	 * @param player Player
	 */
	public void onEvtClose(Player player)
	{
	}
	
	/**
	 * Method getActor.
	 * @return DoorInstance
	 */
	
	public override DoorInstance getActor()
	{
		return (DoorInstance) base.getActor();
	}
	
	/**
	 * Method onEvtAttacked.
	 * @param attacker Creature
	 * @param damage int
	 */
	
	protected override void onEvtAttacked(Creature attacker, int damage)
	{
		Creature actor;
		if ((attacker == null) || ((actor = getActor()) == null))
		{
			return;
		}
		Player player = attacker.getPlayer();
		if (player == null)
		{
			return;
		}
		SiegeEvent siegeEvent1 = player.getEvent(typeof(SiegeEvent));
		SiegeEvent siegeEvent2 = actor.getEvent(typeof(SiegeEvent));
		if ((siegeEvent1 == null) || ((siegeEvent1 == siegeEvent2) && (siegeEvent1.getSiegeClan(SiegeEvent.ATTACKERS, player.getClan()) != null)))
		{
			foreach (NpcInstance npc in actor.getAroundNpc(900, 200))
			{
			    if (!npc.isSiegeGuard())
				{
					continue;
				}
			    npc.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, attacker, Rnd.chance(20) ? 10000 : 2000);
			}
		}
	}
}
}
